			var Episodes = {
				data : null,
				save : function(data) {
					json = JSON.stringify(data);
					i = 0;
					parts = new Array()
					while (sub = json.substr(i, 1024)) {
						parts.push(sub);
						i += 1024;
					}
					System.Gadget.Settings.writeString("episodes_parts", parts.length);
					for (i = 0; i < parts.length; i++) {
						System.Gadget.Settings.writeString("episodes_part"+i.toString(), parts[i]);
					}
					return true;
				},
				view_list_episodes : function(callback) {
					if (this.data != null) {
						callback(this.data);
						return true;
					}
					parts = System.Gadget.Settings.readString("episodes_parts");
				   
					if (/\b\d+\b/.test(parts)) {
						json = "";
						for (i = 0; i < parts; i++) {
							json += System.Gadget.Settings.readString("episodes_part"+i.toString());
						}
						data = JSON.parse(json);
						this.data = data;
						callback(data);
					} else {
						sc = this;
						$.getJSON(
							"http://serials-checker.kex1k.ru/api.php?jsoncallback=?",
							{
								content : "episodes",
								ids : "all"
							},
							function(data) {
								System.Gadget.Settings.writeString("last_update",(new Date()).getTime().toString());
								this.data = data;
								sc.save(data);
								callback(data);
							}
						);
					}
					return true;
				}
			};
			
			var renderEpisode = function(episode) {
				return 	"<div class='caption'>" + episode.serial.replace(/(\ )|(\-)/g, "&nbsp;") + "</div>" +
						"<div class='episode-number'>" + episode.number.replace(/(\ )|(\-)/g, "&nbsp;") + "</div>" +
						"<div class='date'>" + episode.release_date + "</div>" +
						"<div style='clear:left'></div>";
			}
			
			var update = function () {
				Episodes.view_list_episodes(function(data) {
					var serials_check = System.Gadget.Settings.readString("serials_check");
					var episodes_check_released = new Array();
					var episodes_check_notreleased = new Array();
					var content = new Array();
					
					serials_check = JSON.parse(serials_check);
					$(System.Gadget.document).find("#content div").remove();
					for (i = 0; i < data.length; i++) {
						if (search_element(data[i].serial_id, serials_check) >= 0) {
							if (data[i].released == 1) {
								episodes_check_released.push(data[i]);
							} else {
								episodes_check_notreleased.push(data[i]);
							}
						}
					}
					
					if (episodes_check_notreleased.length + episodes_check_released.length == 0) {
						$(System.Gadget.document)
						.find("#content")
						.html('<div style="text-align:center; margin-left: 5px;">У вас не выбранно ни одного сериала, зайдите в настройки и добавьте нужные сериалы к своему списку.<div>');
						return;
					}
					
					d = new Date();
					day = (d.getUTCDate() > 9) ? d.getUTCDate() : "0" + d.getUTCDate().toString();
					month = ((d.getUTCMonth() + 1) > 9) ? d.getUTCMonth()+1 : "0" + (d.getUTCMonth()+1).toString();
					date = day + "." + month;
					
					even = "even";
					for (i = episodes_check_released.length - 1; i >= 0; i--) {
						even = (even == "not-even") ? "even" : "not-even";
						div = 	"<div onmouseover='episodeMouseOver(this);' onmouseout='episodeMouseOut(this);' class='episode " + even + "'>" + renderEpisode(episodes_check_released[i]) + "</div>";
						content[i] = div;
					}
					
					if (episodes_check_notreleased.length == 0 || episodes_check_notreleased[0].release_date != date) {
						div = 	"<div class='episode today'>" + 
									"<div class='caption' title='На сегодня ничего нет.'> - </div>" +
									"<div class='date'> - </div>" +
								"</div>";
						content.push(div);
					}
					if (episodes_check_notreleased.length == 0) {
						div = 	'<div style="text-align: center; width: 100%;" >' +
									'Нет информации о ближайшем выходе эпизодов.' + 
								'</div>';
						content.push(div);
					}
					
					even = "even";
					for (i = 0; i < episodes_check_notreleased.length; i++) {
						if (date == episodes_check_notreleased[i].release_date) {
							div = 	"<div onmouseover='episodeMouseOver(this);' onmouseout='episodeMouseOut(this);' class='episode today'>" + renderEpisode(episodes_check_notreleased[i]) + "</div>";
							content.push(div);
						} else {
							even = (even == "not-even") ? "even" : "not-even";
							div = 	"<div onmouseover='episodeMouseOver(this);' onmouseout='episodeMouseOut(this);' class='episode " + even + "'>" + renderEpisode(episodes_check_notreleased[i]) + "</div>";
							content.push(div);
						}
					}
					
					for (i = 0; i < content.length; i++) {
						$(System.Gadget.document).find("#content").append(content[i]);
					}
					
				});
			};